package com.bcxj.servicemap.remote;

import com.bcxj.internalcommon.constant.AmapConfigConstants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/**
 * ClassName: DicDistrictClient
 * Package: com.bcxj.servicemap.remote
 * Description:
 *
 * @Author BCXJ
 * @Create 2024/10/11 23:22
 * @Version 1.0
 * @Since 1.0
 */
@Component
public class DicDistrictClient {

    @Autowired
    private RestTemplate restTemplate;

    @Value("${amap.key}")
    private String AMAP_KEY;

    /**
     * 获取行政区划
     * @param keyword
     * @return
     */
    public String getDistrict(String keyword){
        StringBuilder url = new StringBuilder();

        url.append(AmapConfigConstants.DISTRICT_URL);
        //下面是请求的网址
        //https://restapi.amap.com/v3/config/district?keywords=北京&subdistrict=3&key=<用户的key>
        url.append("?");
        url.append("keywords=");
        url.append(keyword);
        url.append("&");
        url.append("subdistrict=").append("3");
        url.append("&");
        url.append("key=").append(AMAP_KEY);

        ResponseEntity<String> forEntity = restTemplate.getForEntity(url.toString(), String.class);

        return forEntity.getBody();
    }
}
